package br.com.pnfp.web.control.forms;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

public class DefaultForm extends ActionForm {
	
	private static final long serialVersionUID = -1836149924392148286L;
	
	private String method;
	
	@Override
	public void reset(ActionMapping arg0, HttpServletRequest arg1) {
		Field[] fields = getClass().getDeclaredFields();
		for(Field field : fields) {
			try {
				if(field.getType().equals(FormFile.class)) {
					continue;
				}
				BeanUtils.setProperty(this, field.getName(), null);
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
		}
	}
	
	public String getMethod() {
		return method;
	}	
	public void setMethod(String method) {
		this.method = method;
	}

}
